import React, {Fragment, PureComponent} from 'react';
import {connect} from 'dva';
import router from 'umi/router';
import {Card, Form, Icon, Input, Select, Steps,} from 'antd';
import DescriptionList from '@/components/DescriptionList';
import {getReadableSize, hasInstalledEditApp,} from '@/utils/dsrsUtil';
import TableList from '@/components/TableList';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';
import styles from './PrivateFile.less';
import DirLine from "./sub/DirLine";
const {Description} = DescriptionList;
const FormItem = Form.Item;
const {Step} = Steps;
const {TextArea} = Input;
const {Option} = Select;
const getValue = obj =>
  Object.keys(obj)
    .map(key => obj[key])
    .join(',');

const formLayout = {
  labelCol: {span: 6},
  wrapperCol: {span: 18},
};

/* eslint react/no-multi-comp:0 */
@connect(({homeFileModel, loading}) => ({
  homeFileModel,
  loading: loading.models.homeFileModel,
}))
@Form.create()
class HomeFile extends PureComponent {
  state = {
    selectedRows: [],
    hidefunctions: [],
    currentDirs: [{code: 'index', dirName: '我的文件库', id: ''}],
  };

  columns = [
    {
      title: '名称',
      dataIndex: 'name',
      width: "30%",
      render: (text, row) => {
        return <Fragment>
          <Icon type="folder" theme="filled" style={{color: '#e87e04'}}/>&nbsp;
          <a onClick={() => this.enterSubFile(row)}>{text}</a>
        </Fragment>
      },
    },
  ]
  ;

  componentDidMount() {
    //组织管理员
    this.queryFileHomePage();
  }

  onDirSelect = item => {

  }
  queryFileHomePage = () => {
    const {dispatch} = this.props;
    dispatch({
      type: 'homeFileModel/queryFileHomePage',
    });
  }
  enterSubFile = (row) => {
    const {dispatch} = this.props;
    console.error("row code:" + row.code);
    switch (row.code) {
      case 'index':
        break;
      case 'private_file':
        router.push('/filecenter/private-file');
        break;
      case 'share_file':
        router.push('/filecenter/share');
        break;
      case 'group_file':
        router.push('/filecenter/group');
        break;
      case 'out_side_file':
        router.push('/filecenter/out-file');
        break;

      default:
        break
    }


  }

  render() {
    const {
      homeFileModel: {data, dirTreeList, usersData, groupList, scanData, orgAdmin,},
      loading,
    } = this.props;
    const {
      selectedRows,
      currentDirs,
    } = this.state;


    return (
      <PageHeaderWrapper title="首页">
        <Card bordered={false}>
          <DirLine dirs={currentDirs} onDirSelect={this.onDirSelect}/>
          <div className={styles.tableList}>
            <TableList
              className={styles.tdPadding}
              loading={loading}
              data={data}
              selectedRows={selectedRows}
              hideRowSelection={true}
              columns={this.columns}
            />
          </div>
        </Card>

      </PageHeaderWrapper>
    );
  }
}


export default HomeFile;
